home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / emul / cp4 / c2p_src / c2p_windowcard.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  17KB  |  597 lines

  1. /* :ts=4                            c2p_windowcard.c
  2.  *
  3.  *    cp4 - Commodore C+4 emulator
  4.  *    Copyright (C) 1998 Gáti Gergely
  5.  *
  6.  *    This program is free software; you can redistribute it and/or modify
  7.  *    it under the terms of the GNU General Public License as published by
  8.  *    the Free Software Foundation; either version 2 of the License, or
  9.  *    (at your option) any later version.
  10.  *
  11.  *    This program is distributed in the hope that it will be useful,
  12.  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *    GNU General Public License for more details.
  15.  *
  16.  *    You should have received a copy of the GNU General Public License
  17.  *    along with this program; if not, write to the Free Software Foundation,
  18.  *    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19.  *
  20.  *    e-mail: gatig@dragon.klte.hu
  21.  */
  22. #include <proto/graphics.h>
  23. #include <graphics/gfxbase.h>
  24. #include <proto/exec.h>
  25. #include <exec/alerts.h>
  26. #include <proto/intuition.h>
  27. #include <intuition/pointerclass.h>
  28. #include <proto/gadtools.h>
  29. #include <proto/layers.h>
  30.  
  31. #include "cp4_ver.h"
  32.  
  33. #define C2P_VERSION        "1"
  34. #define C2P_REVISION    "2"
  35. #define C2P_AUTHOR        "gega <Gáti Gergely>"
  36. #define C2P_NAME        "WindowCard"
  37. #define C2P_DATE        DATE
  38. #define C2P_LOCALIZE
  39.  
  40. #include "c2p_module.c"
  41. #include "c2p_windowcard_palette.c"
  42. #include "c2p_color_priority.c"
  43.  
  44.  
  45. struct GfxBase *GfxBase=NULL;
  46. struct IntuitionBase *IntuitionBase=NULL;
  47. struct Library *GadToolsBase=NULL;
  48. struct Library *LayersBase=NULL;
  49. static struct BitMap *bmap;
  50. static struct Window *win=NULL;
  51. static int offx=0,offy=0;
  52. static int maxx,maxy;
  53. static int borhoriz,borvert;
  54. static struct BitMap mybmap;
  55. static void *mypointer=NULL;
  56. static UWORD *mypntchip0=NULL;
  57. static UWORD *mypntchip1=NULL;
  58. static struct ColorMap *colmap=NULL;
  59. static struct BitMap *bmapwpx;
  60. static struct RastPort *tmpraswpx;
  61. static struct RastPort *raswpx;
  62. static int winsleeped=0;
  63. static struct Requester InvisibleRequester;
  64. static LONG PenTable[256];
  65. static unsigned char PenArray[SCRSIZE];
  66. static struct Menu *mMenus=NULL;
  67. static APTR visualinfo=NULL;
  68. /* LORES-POINTER
  69.  */
  70. #define POINTERHEIGHT    31
  71. static UWORD pointerp0[]={ 0,384,384,3504,3504,3504,28080,28080,28080,28086,28086,28086,32758,32758,32766,32766,32764,16380,16376,16376,0,32764,0,32764,32740,32764,32740,32764,32764,32736,28672 };
  72. static UWORD pointerp1[]={ 384,960,4080,8184,8184,32760,65528,65528,65534,65535,65535,65535,65535,65535,65535,65535,65534,32766,32764,32764,65534,65534,65534,32770,32794,32770,32794,32770,32770,32768,32768 };
  73.  
  74. /* prefs
  75.  */
  76. static int WTop,WLeft,WHeight,WWidth,Wx,Wy;
  77. static char *WPubName=NULL;
  78.  
  79. /* Protos
  80.  */
  81. static char *initgfx(void);
  82. static void freegfx(void);
  83. static int mReset(struct IntuiMessage *imsg);
  84. static int mHReset(struct IntuiMessage *imsg);
  85. static int mDebug(struct IntuiMessage *imsg);
  86. static int mPrefs(struct IntuiMessage *imsg);
  87. static int mJump(struct IntuiMessage *imsg);
  88. static int mQuit(struct IntuiMessage *imsg);
  89.  
  90. #define MSG_PROJECT            0
  91. #define MSG_RESET            1
  92. #define MSG_HARDRESET        2
  93. #define MSG_DEBUG            3
  94. #define MSG_PREFS            4
  95. #define MSG_QUIT            5
  96. #define MSG_OPTIONS            6
  97. #define MSG_JUMPSCR            7
  98. #define MSG_INFO            8
  99. #define MSG_ERRVISUALINFO    9
  100. #define MSG_ERRCREATEMENU    10
  101. #define MSG_ERROPENWIN        11
  102. #define MSG_ERRBITMAPATTR    12
  103. #define MSG_ERRBITPNUM        13
  104. #define MSG_ERRFINDCOLMAP    14
  105. #define MSG_ERROBTPENS        15
  106. #define MSG_ERRGRAPHICS        16
  107. #define MSG_ERRINTUITION    17
  108. #define MSG_ERRLAYERS        18
  109. #define MSG_ERRGADTOOLS        19
  110. #define MSG_ERRPOINTER        20
  111. #define MSG_RESET_A            21
  112. #define MSG_HARDRESET_A        22
  113. #define MSG_DEBUG_A            23
  114. #define MSG_PREFS_A            24
  115. #define MSG_QUIT_A            25
  116. #define MSG_JUMPSCR_A        26
  117. #define MSG_NOMEM            27
  118.  
  119. static char *defstr[]={
  120.     "Project",
  121.     "Reset",
  122.     "HardReset",
  123.     "Debug...",
  124.     "Prefs...",
  125.     "Quit",
  126.     "Options",
  127.     "Jump PubScreen",
  128.     "Workbench window driver. Works on GFX cards and AGA too.",
  129.     "Can't find VisualInfo",
  130.     "Can't Create Menu",
  131.     "Can't open Window",
  132.     "Wrong BitMap Attributes",
  133.     "Wrong BitPlane Number",
  134.     "Can't Find ColorMap",
  135.     "Can't Obtain Pens",
  136.     "Can't open graphics.library V39",
  137.     "Can't open intuition.library V39",
  138.     "Can't open layers.library V33",
  139.     "Can't open gadtools.library V37",
  140.     "Can't Create Pointer",
  141.     "R",
  142.     "H",
  143.     "D",
  144.     "P",
  145.     "X",
  146.     "J",
  147.     "Not enough memory",
  148.     NULL
  149. };
  150.  
  151.  
  152. /* Menu
  153.  */
  154. static struct NewMenu mNewMenu[]={
  155.     {    NM_TITLE, (STRPTR)MSG_PROJECT, NULL, 0, NULL, NULL    },
  156.     {    NM_ITEM, (STRPTR)MSG_RESET, (STRPTR)MSG_RESET_A, 0, 0L, (APTR)mReset },
  157.     {    NM_ITEM, (STRPTR)MSG_HARDRESET, (STRPTR)MSG_HARDRESET_A, 0, 0L, (APTR)mHReset },
  158.     {    NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL    },
  159.     {    NM_ITEM, (STRPTR)MSG_DEBUG, (STRPTR)MSG_DEBUG_A, 0, 0L, (APTR)mDebug },
  160.     {    NM_ITEM, (STRPTR)MSG_PREFS, (STRPTR)MSG_PREFS_A, 0, 0L, (APTR)mPrefs },
  161.     {    NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL    },
  162.     {    NM_ITEM, (STRPTR)MSG_QUIT, (STRPTR)MSG_QUIT_A, 0, 0L, (APTR)mQuit },
  163.     {    NM_TITLE, (STRPTR)MSG_OPTIONS, NULL, 0, NULL, NULL    },
  164.     {    NM_ITEM, (STRPTR)MSG_JUMPSCR, (STRPTR)MSG_JUMPSCR_A, 0, 0L, (APTR)mJump },
  165.     {    NM_END, NULL, NULL, 0, 0L, NULL    }
  166. };
  167. static struct NewMenu sNewMenu[]={
  168.     {    NM_TITLE, (STRPTR)MSG_PROJECT, NULL, 0, NULL, NULL    },
  169.     {    NM_ITEM, (STRPTR)MSG_RESET, (STRPTR)MSG_RESET_A, 0, 0L, (APTR)mReset },
  170.     {    NM_ITEM, (STRPTR)MSG_HARDRESET, (STRPTR)MSG_HARDRESET_A, 0, 0L, (APTR)mHReset },
  171.     {    NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL    },
  172.     {    NM_ITEM, (STRPTR)MSG_DEBUG, (STRPTR)MSG_DEBUG_A, 0, 0L, (APTR)mDebug },
  173.     {    NM_ITEM, (STRPTR)MSG_PREFS, (STRPTR)MSG_PREFS_A, 0, 0L, (APTR)mPrefs },
  174.     {    NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL    },
  175.     {    NM_ITEM, (STRPTR)MSG_QUIT, (STRPTR)MSG_QUIT_A, 0, 0L, (APTR)mQuit },
  176.     {    NM_TITLE, (STRPTR)MSG_OPTIONS, NULL, 0, NULL, NULL    },
  177.     {    NM_ITEM, (STRPTR)MSG_JUMPSCR, (STRPTR)MSG_JUMPSCR_A, 0, 0L, (APTR)mJump },
  178.     {    NM_END, NULL, NULL, 0, 0L, NULL    }
  179. };
  180.  
  181.  
  182. char *SAVEDS minfo(void) {
  183. static char in[1024];
  184.     char *s;
  185.     c2p_OpenCatalog(defstr);
  186.     s=STR(MSG_INFO);
  187.     c2p_strncpy(in,s,1023);
  188.     c2p_CloseCatalog();
  189.     return(in);
  190. }
  191.  
  192. /* Handle MenuPick
  193.  */
  194. static int mReset(struct IntuiMessage *imsg) {
  195.     return(RET_RESET);
  196. } // mReset()
  197.  
  198. static int mHReset(struct IntuiMessage *imsg) {
  199.     return(RET_HRESET);
  200. } // mHReset()
  201.  
  202. static int mDebug(struct IntuiMessage *imsg) {
  203.     return(RET_DEBUG);
  204. } // mDebug()
  205.  
  206. static int mPrefs(struct IntuiMessage *imsg) {
  207.     return(RET_PREFS);
  208. } // mPrefs()
  209.  
  210. static int mQuit(struct IntuiMessage *imsg) {
  211.     return(RET_QUIT);
  212. } // mQuit()
  213.  
  214. static int mJump(struct IntuiMessage *imsg) {
  215. static char newname[MAXPUBSCREENNAME+1];
  216.     int r=RET_OK,i;
  217.     char *s;
  218.  
  219.     if(NULL!=(NextPubScreen(vec.c2p_Scr,newname))) {
  220.         if(NULL!=(s=AllocVec(MAXPUBSCREENNAME+1,MEMF_ANY))) {
  221.             freegfx();
  222.             r=RET_NEWWIN;
  223.             for(i=0;newname[i]!='\0';i++);
  224.             CopyMem(newname,s,i+1);
  225.             if(WPubName) FreeVec(WPubName);
  226.             WPubName=s;
  227.             if(NULL!=(initgfx())) {
  228.                 freegfx();
  229.                 // PANIC!!!
  230.                 Alert(AT_Recovery|AG_NoMemory|AO_Unknown);
  231.                 return(RET_ERROR);
  232.             }
  233.         }
  234.     }
  235.     return(r);
  236. } // mJump()
  237.  
  238.  
  239. static INLINE void calcwinsizes() {
  240.     borhoriz=win->BorderRight+win->BorderLeft-1;
  241.     borvert=win->BorderTop+win->BorderBottom-1;
  242.     maxx=SCRWIDTH-(win->Width-borhoriz);
  243.     maxy=SCRHEIGHT-(win->Height-borvert);
  244.     if(offx>maxx) {
  245.         ScrollLayer(0,win->RPort->Layer,-(offx-maxx),0);
  246.         offx=maxx;
  247.     }
  248.     if(offy>maxy) {
  249.         ScrollLayer(0,win->RPort->Layer,0,-(offy-maxy));
  250.         offy=maxy;
  251.     }
  252. }
  253.  
  254.  
  255. static char *initgfx(void) {
  256. static char pname[MAXPUBSCREENNAME+1];
  257.     ULONG r,g,b,wa_top=WA_Top;
  258.     int planes,i,j,mx,my;
  259.  
  260.     for(i=0;i<256;i++) PenTable[i]=-1;
  261.  
  262.     /* Get the required PubScreen
  263.      */
  264.     if(NULL==(vec.c2p_Scr=LockPubScreen(WPubName))) {
  265.         vec.c2p_Scr=LockPubScreen(NULL);
  266.         GetDefaultPubScreen(pname);
  267.         if(WPubName) FreeVec(WPubName);
  268.         for(i=0;pname[i]!='\0';i++);
  269.         if(NULL==(WPubName=AllocVec(i+2,MEMF_ANY))) return(STR(MSG_NOMEM));
  270.         CopyMem(pname,WPubName,i+1);
  271.     }
  272.  
  273.     /* ScreenToFront
  274.      */
  275.     ScreenToFront(vec.c2p_Scr);
  276.  
  277.     /* Get Screen Attribs
  278.      */
  279.     planes=vec.c2p_Scr->BitMap.Depth;
  280.     if(!(visualinfo=GetVisualInfo(vec.c2p_Scr,TAG_DONE))) return(STR(MSG_ERRVISUALINFO));
  281.  
  282.     /* Allocate bitmap
  283.      */
  284.     if(NULL==(bmap=AllocBitMap(SCRWIDTH,SCRHEIGHT,planes,BMF_DISPLAYABLE|BMF_CLEAR,NULL))) return(STR(MSG_NOMEM));
  285.  
  286.     /* SetUp Menu
  287.      */
  288.     for(i=0;sNewMenu[i].nm_Type!=NM_END;i++) {
  289.         mNewMenu[i].nm_Label=sNewMenu[i].nm_Label;
  290.         mNewMenu[i].nm_CommKey=sNewMenu[i].nm_CommKey;
  291.     }
  292.     for(i=0;mNewMenu[i].nm_Type!=NM_END;i++) {
  293.         if(mNewMenu[i].nm_Label!=NM_BARLABEL) mNewMenu[i].nm_Label=STR((long)mNewMenu[i].nm_Label);
  294.         if(mNewMenu[i].nm_CommKey!=NULL) mNewMenu[i].nm_CommKey=STR((long)mNewMenu[i].nm_CommKey);
  295.     }
  296.     if(!(mMenus=CreateMenus(mNewMenu,GTMN_FrontPen,0L,TAG_DONE,0L))) return(STR(MSG_ERRCREATEMENU));
  297.     LayoutMenus(mMenus,visualinfo,GTMN_TextAttr,(ULONG)vec.c2p_Scr->Font,GTMN_NewLookMenus,TRUE,TAG_DONE,0L);
  298.  
  299.     /* Open window
  300.      */
  301.     if(WTop==-1) { wa_top=TAG_IGNORE; WTop=0; }
  302.     if((win=(struct Window *)OpenWindowTags(NULL,
  303.                 WA_Left, WLeft,
  304.                 wa_top, WTop,
  305.                 WA_Width, WWidth,
  306.                 WA_Height, WHeight,
  307.                 WA_Title, (ULONG)"WindowCard",
  308.                 WA_Flags,    WFLG_SIZEGADGET|
  309.                             WFLG_SIZEBBOTTOM|
  310.                             WFLG_DRAGBAR|
  311.                             WFLG_DEPTHGADGET|
  312.                             WFLG_CLOSEGADGET|
  313.                             WFLG_SUPER_BITMAP|
  314.                             WFLG_GIMMEZEROZERO|
  315.                             WFLG_ACTIVATE,
  316.                 WA_SuperBitMap, (ULONG)bmap,
  317.                 WA_AutoAdjust, TRUE,
  318.                 WA_RptQueue, 25,
  319.                 WA_IDCMP,     IDCMP_MOUSEMOVE|
  320.                             IDCMP_CLOSEWINDOW|
  321.                             IDCMP_MENUPICK|
  322.                             IDCMP_NEWSIZE|
  323.                             IDCMP_MOUSEBUTTONS,
  324.                 WA_PubScreen, (ULONG)vec.c2p_Scr,
  325.                 WA_PubScreenFallBack, TRUE,
  326.                 WA_NewLookMenus, TRUE,
  327.                 TAG_DONE,0L ))==NULL)
  328.         return(STR(MSG_ERROPENWIN));
  329.     SetMenuStrip(win,mMenus);
  330.     vec.c2p_Win=win;
  331.     winsleeped=0;
  332.     offx=offy=0;
  333.     calcwinsizes();
  334.     WindowLimits(win,borhoriz+80,borvert+20,SCRWIDTH+borhoriz,borvert+SCRHEIGHT);
  335.     offx+=Wx;        offy+=Wy;
  336.     mx=Wx;            my=Wy;
  337.     if(offx<0)        { mx-=offx; offx=0; }
  338.     if(offx>maxx)    { mx-=offx-maxx; offx=maxx; }
  339.     if(offy<0)        { my-=offy; offy=0; }
  340.     if(offy>maxy)    { my-=offy-maxy; offy=maxy; }
  341.     ScrollLayer(0,win->RPort->Layer,mx,my);
  342.  
  343.     /* Allocate & Init TMP rasters for WritePixel...
  344.      */
  345.     bmapwpx=AllocBitMap(SCRWIDTH,1,planes,BMF_CLEAR,NULL);
  346.     if(bmapwpx==NULL) return(STR(MSG_NOMEM));
  347.     tmpraswpx=AllocVec(sizeof(struct RastPort),MEMF_ANY);
  348.     if(tmpraswpx==NULL) return(STR(MSG_NOMEM));
  349.     InitRastPort(tmpraswpx);
  350.     tmpraswpx->BitMap=bmapwpx;
  351.     raswpx=AllocVec(sizeof(struct RastPort),MEMF_ANY);
  352.     if(raswpx==NULL) return(STR(MSG_NOMEM));
  353.     InitRastPort(raswpx);
  354.     raswpx->BitMap=bmap;
  355.  
  356.     /* SetUp PenTable
  357.      */
  358.     if(NULL==(colmap=vec.c2p_Scr->ViewPort.ColorMap)) return(STR(MSG_ERRFINDCOLMAP));
  359.     for(i=0;i<256;i++) {
  360.         j=ColorPriority[i]*3;
  361.         r=Palette[j];
  362.         g=Palette[j+1];
  363.         b=Palette[j+2];
  364.         if(-1==(PenTable[ColorPriority[i]]=ObtainBestPen(colmap,r,g,b,OBP_Precision,PRECISION_GUI,TAG_DONE))) return(STR(MSG_ERROBTPENS));
  365.     }
  366.     return(NULL);
  367. } // initgfx()
  368.  
  369.  
  370. static void freegfx(void) {
  371.     int i;
  372.     mawake();
  373.     if(GfxBase) {
  374.         WaitTOF();
  375.         if(colmap) for(i=0;i<256;i++) if(PenTable[i]!=-1) ReleasePen(colmap,PenTable[i]);
  376.     }
  377.     if(win) {
  378.         WTop=win->TopEdge;
  379.         WLeft=win->LeftEdge;
  380.         WHeight=win->Height;
  381.         WWidth=win->Width;
  382.         vec.c2p_AddOptionInt("WINTOP",WTop);
  383.         vec.c2p_AddOptionInt("WINLEFT",WLeft);
  384.         vec.c2p_AddOptionInt("WINHEIGHT",WHeight);
  385.         vec.c2p_AddOptionInt("WINWIDTH",WWidth);
  386.         Wx=offx;
  387.         Wy=offy;
  388.         vec.c2p_AddOptionInt("OFFX",Wx);
  389.         vec.c2p_AddOptionInt("OFFY",Wy);
  390.         ClearMenuStrip(win);
  391.         CloseWindow(win);
  392.         win=NULL;
  393.     }
  394.     vec.c2p_Win=NULL;
  395.     if(mMenus) { FreeMenus(mMenus); mMenus=NULL; }
  396.     if(visualinfo) { FreeVisualInfo(visualinfo); visualinfo=NULL; }
  397.     if(vec.c2p_Scr) {
  398.         vec.c2p_AddOptionStr("PUBSCREEN",WPubName);
  399.         UnlockPubScreen(NULL,vec.c2p_Scr);
  400.         vec.c2p_Scr=NULL;
  401.     }
  402.     if(bmap) { FreeBitMap(bmap); bmap=NULL; }
  403.     if(bmapwpx) { FreeBitMap(bmapwpx); bmapwpx=NULL; }
  404.     if(tmpraswpx) { FreeVec(tmpraswpx); tmpraswpx=NULL; }
  405.     if(raswpx) { FreeVec(raswpx); raswpx=NULL; }
  406. } // freegfx()
  407.  
  408.  
  409. char *SAVEDS minit(ULONG scrmode, ULONG overscan, unsigned char *linedeltatab) {
  410.     int i;
  411.     ULONG res;
  412.     char *s;
  413.  
  414.     c2p_OpenCatalog(defstr);
  415.  
  416.     if(!(GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",39))) return(STR(MSG_ERRGRAPHICS));
  417.     if(!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",39))) return(STR(MSG_ERRINTUITION));
  418.     if(!(GadToolsBase=OpenLibrary("gadtools.library",37))) return(STR(MSG_ERRGADTOOLS));
  419.     if(!(LayersBase=OpenLibrary("layers.library",33))) return(STR(MSG_ERRLAYERS));
  420.  
  421.     /* Set up pointer
  422.      */
  423.     if(NULL==(mypntchip0=AllocVec((POINTERHEIGHT+1)*2,MEMF_CHIP))) return(STR(MSG_NOMEM));
  424.     if(NULL==(mypntchip1=AllocVec((POINTERHEIGHT+1)*2,MEMF_CHIP))) return(STR(MSG_NOMEM));
  425.     CopyMem(pointerp0,mypntchip0,2*POINTERHEIGHT);
  426.     CopyMem(pointerp1,mypntchip1,2*POINTERHEIGHT);
  427.     InitBitMap(&mybmap,2,16,POINTERHEIGHT);
  428.     mybmap.Planes[0]=(PLANEPTR)mypntchip0;
  429.     mybmap.Planes[1]=(PLANEPTR)mypntchip1;
  430.     res=POINTERYRESN_DEFAULT;
  431.     if(((GfxBase->ChipRevBits0&GFXF_HR_AGNUS)!=0)&&((GfxBase->ChipRevBits0&GFXF_HR_DENISE)!=0)) res=POINTERXRESN_SCREENRES;
  432.     mypointer=NewObject(NULL,"pointerclass",
  433.         POINTERA_BitMap, (ULONG)&mybmap,
  434.         POINTERA_XOffset, -6,
  435.         POINTERA_WordWidth, 1,
  436.         POINTERA_XResolution, res,
  437.         POINTERA_YResolution, res,
  438.         TAG_DONE );
  439.     if(mypointer==NULL) return(STR(MSG_ERRPOINTER));
  440.  
  441.     /* Get Options
  442.      */
  443.     Wx=vec.c2p_GetOptionInt("OFFX",0);
  444.     Wy=vec.c2p_GetOptionInt("OFFY",0);
  445.     WTop=vec.c2p_GetOptionInt("WINTOP",-1);
  446.     WLeft=vec.c2p_GetOptionInt("WINLEFT",0);
  447.     WHeight=vec.c2p_GetOptionInt("WINHEIGHT",303);
  448.     WWidth=vec.c2p_GetOptionInt("WINWIDTH",359);
  449.     s=vec.c2p_GetOptionStr("PUBSCREEN","Workbench");
  450.     for(i=0;s[i]!='\0';i++);
  451.     if(NULL==(WPubName=AllocVec(i+2,MEMF_ANY))) return(STR(MSG_NOMEM));
  452.     CopyMem(s,WPubName,i+1);
  453.  
  454.     return(initgfx());
  455. } // minit
  456.  
  457.  
  458. void SAVEDS mfree(void) {
  459.     freegfx();
  460.     if(mypntchip0) { FreeVec(mypntchip0); mypntchip0=NULL; }
  461.     if(mypntchip1) { FreeVec(mypntchip1); mypntchip1=NULL; }
  462.     if(mypointer) { DisposeObject(mypointer); mypointer=NULL; }
  463.     if(GfxBase) CloseLibrary((struct Library *)GfxBase);
  464.     if(IntuitionBase) { CloseLibrary((struct Library *)IntuitionBase); IntuitionBase=NULL; }
  465.     if(GadToolsBase) { CloseLibrary(GadToolsBase); GadToolsBase=NULL; }
  466.     if(LayersBase) CloseLibrary(LayersBase);
  467.     c2p_CloseCatalog();
  468.     return;
  469. } // free
  470.  
  471.  
  472. int SAVEDS mdo(unsigned char *chunky,unsigned char *delta,int numscreen) {
  473.     return(mdofull(chunky,numscreen));
  474. } // do
  475.  
  476.  
  477. int SAVEDS mdofull(unsigned char *chunky,int numscreen) {
  478.     struct IntuiMessage *imsg;
  479.     struct MenuItem *n;
  480.     int (*func)(struct IntuiMessage *);
  481.     int ret=RET_OK,i,move=0,lastx=0,lasty=0;
  482.     unsigned char *p,*c;
  483.  
  484.     while((imsg=(struct IntuiMessage *)RemHead(&vec.c2p_MsgList))) {
  485.         switch(imsg->Class) {
  486.             case IDCMP_CLOSEWINDOW :
  487.                 ret=RET_QUIT;
  488.                 break;
  489.             case IDCMP_MENUPICK :
  490.                 while(imsg->Code!=MENUNULL) {
  491.                     n=ItemAddress(mMenus,imsg->Code);
  492.                     func=(void *)(GTMENUITEM_USERDATA(n));
  493.                     ret=func(imsg);
  494.                     if(ret==RET_NEWWIN||ret==RET_ERROR) {
  495.                         move=0;
  496.                         break;
  497.                     }
  498.                     imsg->Code=n->NextSelect;
  499.                 }
  500.                 break;
  501.             case IDCMP_NEWSIZE :
  502.                 calcwinsizes();
  503.                 break;
  504.             case IDCMP_MOUSEBUTTONS :
  505.                 if(imsg->Code==SELECTDOWN) {
  506.                     move=1;
  507.                     lastx=imsg->MouseX;
  508.                     lasty=imsg->MouseY;
  509.                 } else move=0;
  510.                 break;
  511.         }
  512.     }
  513.  
  514.     /* Handle Drag Window
  515.      */
  516.     if(move!=0) {
  517.         int mx,my,class,t1,t2;
  518.  
  519.         ReportMouse(TRUE,win);
  520.         SetWindowPointer(win,WA_Pointer,(ULONG)mypointer,TAG_DONE);
  521.         while(move!=0) {
  522.             WaitPort(win->UserPort);
  523.             imsg=(struct IntuiMessage *)GetMsg(win->UserPort);
  524.             mx=imsg->MouseX;
  525.             my=imsg->MouseY;
  526.             class=imsg->Class;
  527.             ReplyMsg((struct Message *)imsg);
  528.             switch(class) {
  529.                 case IDCMP_MOUSEBUTTONS :
  530.                     move=0;
  531.                     break;
  532.                 case IDCMP_MOUSEMOVE :
  533.                     offx+=lastx-mx;    offy+=lasty-my;
  534.                     t1=mx;            t2=my;
  535.                     mx=lastx-mx;    my=lasty-my;
  536.                     lastx=t1;        lasty=t2;
  537.                     if(offx<0)        { mx-=offx; offx=0; }
  538.                     if(offx>maxx)    { mx-=offx-maxx; offx=maxx; }
  539.                     if(offy<0)        { my-=offy; offy=0; }
  540.                     if(offy>maxy)    { my-=offy-maxy; offy=maxy; }
  541.                     ScrollLayer(0,win->RPort->Layer,mx,my);
  542.                     break;
  543.             }
  544.         }
  545.         SetWindowPointer(win,TAG_DONE);
  546.         ReportMouse(FALSE,win);
  547.     }
  548.  
  549.     if(chunky!=NULL) {
  550.         /* Convert chunky into PenArray
  551.          */    
  552.         i=SCRSIZE;
  553.         c=chunky;
  554.         p=PenArray;
  555.         do { *p++=PenTable[*c++]; } while(--i);
  556.  
  557.         if(ret!=RET_NEWWIN||ret!=RET_ERROR) {
  558.             /* Do the c2p
  559.              */
  560.             WritePixelArray8(raswpx,0,0,SCRWIDTH-1,SCRHEIGHT-1,PenArray,tmpraswpx);
  561.  
  562.             /* Copy into the window
  563.              */
  564.             LockLayerRom(win->RPort->Layer);
  565.             CopySBitMap(win->RPort->Layer);
  566.             UnlockLayerRom(win->RPort->Layer);
  567.         }
  568.     }
  569.     return(ret);
  570. } // dofull
  571.  
  572.  
  573. int SAVEDS mdont(void) {
  574.     return(mdofull(NULL,0));
  575. } // dont
  576.  
  577.  
  578. void SAVEDS msleep(void) {
  579.     if(win) {
  580.         InitRequester(&InvisibleRequester);
  581.         Request(&InvisibleRequester,win);
  582.         SetWindowPointer(win,WA_BusyPointer,TRUE,TAG_DONE);
  583.         winsleeped=1;
  584.     }
  585. }
  586.  
  587.  
  588. void SAVEDS mawake(void) {
  589.     if(winsleeped) {
  590.         if(win) {
  591.             EndRequest(&InvisibleRequester,win);
  592.             SetWindowPointerA(win,NULL);
  593.             winsleeped=0;
  594.         }
  595.     }
  596. }
  597.